{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import geopandas as gpd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = gpd.read_file(\"outputs/d2-events-2d-230929_SVI_shapefile.geojson\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['ST', 'STATE', 'ST_ABBR', 'STCNTY', 'COUNTY', 'FIPS', 'LOCATION',\n",
       "       'AREA_SQMI', 'E_TOTPOP', 'M_TOTPOP',\n",
       "       ...\n",
       "       'hws5', 'ws5', 'heatday_2d', 'smoke_pm_non_zero_2d', 'wfday_2d',\n",
       "       '_hws_2d', 'hs_2d', 'hws_2d', 'ws_2d', 'geometry'],\n",
       "      dtype='object', length=181)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Interestingly, wildfire burn zones (Fig. 1B) and wildfire smoke (Fig. 1C) showed very different spatial distributions. \n",
    "\n",
    "For instance, Montana recorded 751 tract-days of exposure to wildfire smoke but only 29 tract-days of wildfire burn zone exposure. \n",
    "\n",
    "Similarly, Colorado registered 445 days tract-days of wildfire smoke exposure while only experiencing 3 tract-days with wildfire burn zones."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ST</th>\n",
       "      <th>STATE</th>\n",
       "      <th>ST_ABBR</th>\n",
       "      <th>STCNTY</th>\n",
       "      <th>COUNTY</th>\n",
       "      <th>FIPS</th>\n",
       "      <th>LOCATION</th>\n",
       "      <th>AREA_SQMI</th>\n",
       "      <th>E_TOTPOP</th>\n",
       "      <th>M_TOTPOP</th>\n",
       "      <th>...</th>\n",
       "      <th>hws5</th>\n",
       "      <th>ws5</th>\n",
       "      <th>heatday_2d</th>\n",
       "      <th>smoke_pm_non_zero_2d</th>\n",
       "      <th>wfday_2d</th>\n",
       "      <th>_hws_2d</th>\n",
       "      <th>hs_2d</th>\n",
       "      <th>hws_2d</th>\n",
       "      <th>ws_2d</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10860</th>\n",
       "      <td>08</td>\n",
       "      <td>Colorado</td>\n",
       "      <td>CO</td>\n",
       "      <td>08001</td>\n",
       "      <td>Adams</td>\n",
       "      <td>08001007801</td>\n",
       "      <td>Census Tract 78.01, Adams County, Colorado</td>\n",
       "      <td>0.247698</td>\n",
       "      <td>4274</td>\n",
       "      <td>647</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>260</td>\n",
       "      <td>662</td>\n",
       "      <td>0</td>\n",
       "      <td>802</td>\n",
       "      <td>120</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>MULTIPOLYGON (((-104.88465 39.74381, -104.8752...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10861</th>\n",
       "      <td>08</td>\n",
       "      <td>Colorado</td>\n",
       "      <td>CO</td>\n",
       "      <td>08001</td>\n",
       "      <td>Adams</td>\n",
       "      <td>08001007802</td>\n",
       "      <td>Census Tract 78.02, Adams County, Colorado</td>\n",
       "      <td>0.246091</td>\n",
       "      <td>4491</td>\n",
       "      <td>767</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>242</td>\n",
       "      <td>662</td>\n",
       "      <td>0</td>\n",
       "      <td>790</td>\n",
       "      <td>114</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>MULTIPOLYGON (((-104.86580 39.74379, -104.8616...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10862</th>\n",
       "      <td>08</td>\n",
       "      <td>Colorado</td>\n",
       "      <td>CO</td>\n",
       "      <td>08001</td>\n",
       "      <td>Adams</td>\n",
       "      <td>08001007900</td>\n",
       "      <td>Census Tract 79, Adams County, Colorado</td>\n",
       "      <td>0.632390</td>\n",
       "      <td>5561</td>\n",
       "      <td>694</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>260</td>\n",
       "      <td>662</td>\n",
       "      <td>0</td>\n",
       "      <td>802</td>\n",
       "      <td>120</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>MULTIPOLYGON (((-104.88466 39.74747, -104.8801...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10863</th>\n",
       "      <td>08</td>\n",
       "      <td>Colorado</td>\n",
       "      <td>CO</td>\n",
       "      <td>08001</td>\n",
       "      <td>Adams</td>\n",
       "      <td>08001008000</td>\n",
       "      <td>Census Tract 80, Adams County, Colorado</td>\n",
       "      <td>0.755272</td>\n",
       "      <td>5713</td>\n",
       "      <td>992</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>242</td>\n",
       "      <td>662</td>\n",
       "      <td>0</td>\n",
       "      <td>790</td>\n",
       "      <td>114</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>MULTIPOLYGON (((-104.86592 39.75474, -104.8612...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10864</th>\n",
       "      <td>08</td>\n",
       "      <td>Colorado</td>\n",
       "      <td>CO</td>\n",
       "      <td>08001</td>\n",
       "      <td>Adams</td>\n",
       "      <td>08001008100</td>\n",
       "      <td>Census Tract 81, Adams County, Colorado</td>\n",
       "      <td>1.049077</td>\n",
       "      <td>1440</td>\n",
       "      <td>193</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>242</td>\n",
       "      <td>697</td>\n",
       "      <td>0</td>\n",
       "      <td>823</td>\n",
       "      <td>116</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>MULTIPOLYGON (((-104.84706 39.74378, -104.8470...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 181 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       ST     STATE ST_ABBR STCNTY COUNTY         FIPS  \\\n",
       "10860  08  Colorado      CO  08001  Adams  08001007801   \n",
       "10861  08  Colorado      CO  08001  Adams  08001007802   \n",
       "10862  08  Colorado      CO  08001  Adams  08001007900   \n",
       "10863  08  Colorado      CO  08001  Adams  08001008000   \n",
       "10864  08  Colorado      CO  08001  Adams  08001008100   \n",
       "\n",
       "                                         LOCATION  AREA_SQMI  E_TOTPOP  \\\n",
       "10860  Census Tract 78.01, Adams County, Colorado   0.247698      4274   \n",
       "10861  Census Tract 78.02, Adams County, Colorado   0.246091      4491   \n",
       "10862     Census Tract 79, Adams County, Colorado   0.632390      5561   \n",
       "10863     Census Tract 80, Adams County, Colorado   0.755272      5713   \n",
       "10864     Census Tract 81, Adams County, Colorado   1.049077      1440   \n",
       "\n",
       "       M_TOTPOP  ...  hws5  ws5  heatday_2d  smoke_pm_non_zero_2d  wfday_2d  \\\n",
       "10860       647  ...     0    0         260                   662         0   \n",
       "10861       767  ...     0    0         242                   662         0   \n",
       "10862       694  ...     0    0         260                   662         0   \n",
       "10863       992  ...     0    0         242                   662         0   \n",
       "10864       193  ...     0    0         242                   697         0   \n",
       "\n",
       "       _hws_2d  hs_2d  hws_2d  ws_2d  \\\n",
       "10860      802    120       0      0   \n",
       "10861      790    114       0      0   \n",
       "10862      802    120       0      0   \n",
       "10863      790    114       0      0   \n",
       "10864      823    116       0      0   \n",
       "\n",
       "                                                geometry  \n",
       "10860  MULTIPOLYGON (((-104.88465 39.74381, -104.8752...  \n",
       "10861  MULTIPOLYGON (((-104.86580 39.74379, -104.8616...  \n",
       "10862  MULTIPOLYGON (((-104.88466 39.74747, -104.8801...  \n",
       "10863  MULTIPOLYGON (((-104.86592 39.75474, -104.8612...  \n",
       "10864  MULTIPOLYGON (((-104.84706 39.74378, -104.8470...  \n",
       "\n",
       "[5 rows x 181 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp = data[data.ST_ABBR.isin(['MT', 'CO'])]\n",
    "temp.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ST_ABBR\n",
       "CO    1447\n",
       "MT     319\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# number of census tracts per state\n",
    "\n",
    "temp['ST_ABBR'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>wfday</th>\n",
       "      <th>smoke_pm_non_zero</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ST_ABBR</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>CO</th>\n",
       "      <td>5048</td>\n",
       "      <td>659647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MT</th>\n",
       "      <td>9325</td>\n",
       "      <td>239814</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         wfday  smoke_pm_non_zero\n",
       "ST_ABBR                          \n",
       "CO        5048             659647\n",
       "MT        9325             239814"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp.groupby('ST_ABBR')[['wfday', 'smoke_pm_non_zero']].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "29.231974921630094"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# For instance, Montana recorded 751 tract-days of exposure to wildfire smoke but only 29 tract-days of wildfire burn zone exposure. \n",
    "\n",
    "# exposure to wildfire burn zones in mt\n",
    "\n",
    "9325/319"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "751.7680250783699"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "239814/319"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "455.87214927436077"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "659647/1447"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.4885970974429856"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5048/1447"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
